<script lang="ts" setup>
import { Page } from '@vben/common-ui';

import { Card, message } from 'ant-design-vue';

import { useVbenForm } from '#/adapter/form';

const [BaseForm, formApi] = useVbenForm({
  // 所有表单项共用，可单独在表单内覆盖
  commonConfig: {
    // 所有表单项
    componentProps: {
      class: 'w-full',
    },
  },
  // 使用 tailwindcss grid布局
  // 提交函数
  handleSubmit: onSubmit,
  // 垂直布局，label和input在不同行，值为vertical
  layout: 'horizontal',
  // 水平布局，label和input在同一行
  schema: [
    {
      // 组件需要在 #/adapter.ts内注册，并加上类型
      component: 'Input',
      // 对应组件的参数
      componentProps: {
        placeholder: '请输入活动标题',
      },
      // 字段名
      fieldName: 'field1',
      // 界面显示的label
      label: '活动标题',
    },
    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        filterOption: true,
        options: [
          {
            label: '工会活动',
            value: '1',
          },
          {
            label: '协会活动',
            value: '2',
          },
        ],
        placeholder: '请选择',
        showSearch: true,
      },
      fieldName: 'fieldOptions',
      label: '活动类别',
    },
    {
      component: 'RangePicker',
      fieldName: 'rangePicker',
      label: '活动时间',
    },
    {
      component: 'Input',
      componentProps: {
        placeholder: '活动地点',
      },
      fieldName: 'field2',
      label: '活动地点',
    },
    {
      component: 'Input',
      componentProps: {
        placeholder: '活动描述',
      },
      fieldName: 'field2',
      label: '活动描述',
    },
    {
      component: 'Textarea',
      componentProps: {
        placeholder: '活动流程',
      },
      fieldName: 'field2',
      label: '活动流程',
    },
    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        filterOption: true,
        options: [
          {
            label: '人数上限',
            value: '1',
          },
          {
            label: '部门限制',
            value: '2',
          },
        ],
        placeholder: '请选择',
        showSearch: true,
      },
      fieldName: 'fieldOptions',
      label: '活动限制',
    },
    {
      component: 'DatePicker',
      componentProps: {
        placeholder: '',
      },
      fieldName: 'field2',
      label: '报名截止时间',
    },
  ],
  // 大屏一行显示3个，中屏一行显示2个，小屏一行显示1个
  wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
});

function onSubmit(values: Record<string, any>) {
  message.success({
    content: `form values: ${JSON.stringify(values)}`,
  });
}
</script>

<template>
  <Page>
    <Card title="创建活动">
      <BaseForm />
    </Card>
  </Page>
</template>
